from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):

    mobile = models.CharField(max_length=11, unique=True, verbose_name="手机号")
    avatar = models.ImageField(null=True, blank=True, verbose_name='用户头像')
    real_name = models.CharField(max_length=32, null=True, verbose_name="真实姓名")
    id_card = models.CharField(max_length=20, null=True, verbose_name="身份证号")

    def avatar_url(self):
        """新增时如果未添加图片，则使用默认图片"""
        if self.avatar and hasattr(self.avatar, 'url'):
            return self.avatar.url
        else:
            return '20201226211222243.jpeg'

    class Meta:
        db_table = "tb_user"
